package edu.sctu.jarime.june.day20150616.CharStreamFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

/**
 * Created by user19 on 2015/6/16.
 */
public class CharStreamFileUtil {

    public static void readCharStream(File srcfile) throws  Exception{
        FileInputStream fileInputStream = new FileInputStream(srcfile);
        InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream,"utf-8");
        //当文件内容输出时不乱码就可以使用默认的编码格式，如果乱码就需要改成要读取的文件的对应编码格式
        int a;
        char[] buffer = new char[2014];
        //批量读取，放入buffer这个字符数组，从第0个位置开始放置，每次最多放置buffer.length个，
        //返回的是读到的字符的个数
        while ((a=inputStreamReader.read(buffer,0,buffer.length))!=-1){
            System.out.println(new String(buffer,0,a));
        }
    }
}
